package com.extremelylargepackage.entity;

import android.util.Log;

import com.extremelylargepackage.GameResources;

public class AiBrave implements AiMoveComponent
{
	private Enemy _me;
	
	private float _upperYBounds;
	private float _lowerYBounds;
	private long _wait;
	
	private long _timeSinceMove;
	
	public AiBrave(float lowerY, float upperY, long wait)
	{
		_lowerYBounds = lowerY;
		_upperYBounds = upperY;
		_wait = wait;
		_timeSinceMove = 0;
	}
	
	@Override
	public void setSelf(Enemy me) 
	{
		_me = me;	
	}

	@Override
	public void performMove(long time) 
	{
		if(_timeSinceMove >= _wait)
		{
			float newY = (float)(Math.random() * (_lowerYBounds - _upperYBounds)) + _upperYBounds;
			float newX = _me._player.getLocX();
			_me._dirY = newY - _me._locY;
			_me._dirX = newX - _me._locX;
			_timeSinceMove = 0;
			Log.d("AIBRAVE", "newX : " + newY + ", newY : " + newX);
		}
		else if(_me._dirX < 1 && _me._dirY < 1)
		{
			if(_me._weapon != null)
				_me._weapon.fire();
			_timeSinceMove += time;
		}
	}

	@Override
	public boolean finished() 
	{
		return false;
	}
	
	@Override
	public Object clone()
	{
		return new AiBrave(_lowerYBounds, _upperYBounds, _wait);
	}

}
